package com.xhs.main.controller.yfb;


import com.xhs.main.entity.result.LayuiResponseResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @create 2020-10-25 21:53
 */
@RestController
public class UploadFileController {

    @RequestMapping("/yfb/upload")
    public LayuiResponseResult uploadFiles(MultipartFile file) {  //设计对象，其实可能是测试对象
        String path = "D:\\xhs";
        String fileName = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + file.getOriginalFilename();
        File newFile = new File(path, fileName);
        try {
            file.transferTo(newFile);
            return new LayuiResponseResult(0, "", 1, path + "\\" + fileName);
        } catch (IOException e) {
            e.printStackTrace();
            return new LayuiResponseResult(500, "", 1, null);
        }
    }
}
